<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>问卷列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <!-- 查询表单 -->
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">垫款单</div>
                    <div class="field">
                        <div class="field">
                            <input type="text" id="billNm" name="billNm" class="ui-textbox" ligerui="width: 160"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表编号</div>
                    <div class="field">
                        <div class="field">
                            <input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">所属公司</div>
                    <div class="field">
                        <input type="text" id="companyNm" name="companyNm" class="ui-textbox" ligerui="width: 160"
                               value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">问卷名称</div>
                    <div class="field">
                        <div class="field">
                            <input type="text" id="qtnNm" name="qtnNm" class="ui-textbox" ligerui="width: 160"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">问卷状态</div>
                    <div class="field">
                        <select name="qtnStsCd" id="qtnStsCd">
                            <option value="">请选择</option>
                            <c:forEach items="${qtnStsCdList }" var="item">
                                <option value="${item.key }">${item.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">任务人</div>
                    <div class="field">
                        <select name="allocSts" id="allocSts" data-value=" ">
                            <option value="" selected="selected">请选择</option>
                            <option value="2">未分配</option>
                            <option value="1">已分配</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">任务人工号</div>
                    <div class="field">
                        <input type="text" id="cstMgrCode" name="cstMgrCode" class="ui-textbox" ligerui="width: 160"
                               value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">问卷结果</div>
                    <div class="field">
                        <select name="qtnRstCd" id="qtnRstCd">
                            <option value="">请选择</option>
                            <c:forEach items="${qtnResultList }" var="item">
                                <option value="${item.key }">${item.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否相符</div>
                    <div class="field">
                        <select name="isMatch" id="isMatch">
                            <option value="">请选择</option>
                            <c:forEach items="${isMatchList }" var="item">
                                <option value="${item.key }">${item.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" class="sq-button-round" onclick="searchBtnEvent()">查询</span>
                    <span id="clearBtn" class="sq-button-round" onclick="clearBtnEvent()">清空</span>
                </div>
            </div>
        </form>
    </div>
    <!-- 列表显示块 -->
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        initForm();//初始化表单
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
    });

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/dk/dkquestnelog/initList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {display: '垫款单', name: 'billNm', minWidth: 100, align: 'center', enabledSort: true},
                {display: '生成时间', name: 'crtTm', minWidth: 100, align: 'center', enabledSort: true,render:function (rowdata) {
                        return DateUtils.formatDateToString(rowdata.crtTm,DateUtils.YYYY_MM_DD);
                    }},
                {display: '支付表号', name: 'paySchNo', minWidth: 100, enabledSort: true},
                {display: '承租人', name: 'cstNm', minWidth: 150, enabledSort: true},
                {display: '公司', name: 'cstMgrOrgNm', minWidth: 100, align: 'center', enabledSort: true},
                {display: '问卷名称', name: 'qtnNm', minWidth: 80, align: 'center', enabledSort: true,render:function(rowdata){
                        var res = "<a href=\"javascript:view('"+rowdata.ruleFlag+"')\">" + rowdata.qtnNm + "</a>"
                        return res;
                    }},
                {display: '任务人', name: 'cstMgrNm', minWidth: 80, align: 'center', enabledSort: true},
                {display: '问卷结果', name: 'qtnRstCd', minWidth: 100, align: 'center', enabledSort: true,render: function (rowdata, rowindex, value){
                        if(rowdata.qtnRstCd){
                            var a = rowdata.qtnRstCd;
                            if(a==1){
                                return "已保存";
                            }else if(a==2){
                                return "预期逾期追加";
                            }else if(a==3){
                                return "预期拖回";
                            }else if(a==4){
                                return "预期还款";
                            }else if(a==5){
                                return "出险严重";
                            }else if(a==6){
                                return "出险其他"
                            }
                        }
                    }},
                {display: '是否不符', name: 'isMatch', minWidth: 120, align: 'center', enabledSort: true,render: function (rowdata, rowindex, value){
                        if(rowdata.isMatch){
                            if(rowdata.isMatch=="0"){
                                return "不相符";
                            }else if(rowdata.isMatch=="1"){
                                return "相符";
                            }
                        }
                    }},
                {
                    display: '操作', width: 200, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var res = "";
                        <sys:funcAuth resCd="dkquestionAssignBtn">

                            var v3 = '<a class="sq-button-hasicon" href="javascript:assign(';
                            v3 += "'" + rowdata.id + "'";
                            v3 += ')"><i class="sqBtnIco_4"></i>分配任务人</a>';
                            // TODO 分配权限
                            res += v3
                        </sys:funcAuth>
                        var h = '<a class="sq-button-hasicon" href="javascript:modify(';
                        h += "'" + rowdata.ruleFlag + "','" + rowdata.qtnStsCd + "','"+ rowdata.qtnType + "','"+rowdata.id+"'";
                        h += ')"><i class="sqBtnIco_4"></i>填写问卷</a>';
                        if(rowdata.qtnStsCd!=2){ //已保存问卷不修改
                            res += h ;
                        }
                        return res ;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: false,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,//列表是否有选择框
            rownumbers: true//列表是否有行号
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        grid.options.isSingleCheck = false;//列表是否为单选
    }


    //查询按钮事件
    function searchBtnEvent() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    }

    //清空按钮事件
    function clearBtnEvent() {
        var form = new liger.get("searchBar");
        form.setData({
            billNm: "",
            paySchNo: "",
            companyNm: "",
            qtnNm: "",
            qtnStsCd:"",
            allocSts:"",
            cstMgrCode:"",
            qtnRstCd:"",
            isMatch:""
        });
    }

    var callback = function () {
        grid.reload();
    };
    function assign(id){
        $.ligerDialog.SQopen({
            width: 650,
            height: 500,
            title: '分配任务',
            url: '<%=path%>/dk/dkquestnelog/toAssignPage.do',
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ],
            data: {id: id},
        });
    }
    var onCancel = function (item, Dialog) {
        Dialog.hide();
    };

    /**
     * 修改或是新增问卷
     * @param id ruleFlag
     * @param status 问卷状态  未作答就新增，已保存就修改，提交就不能修改了。
     * @param type 是否出险
     * @param id qtnLogId
     */
    function modify(ruleFlag,status,type,id){
        if(status==1){ //update
            parent.Add_navTab('dk_qtn_modify'+ruleFlag,'答卷','/dk/dkquestnelog/toUpdatePage.do?ruleFlag='+ruleFlag,callback);
            // parent.parent.mainApp.f_addTab('dk_qtn_modify'+ruleFlag,'客户详情','/dk/dkquestnelog/toUpdatePage.do?ruleFlag='+ruleFlag);
        }else if(status==0){ //save
            // 判断试卷类型
            if(type==0){ //未出险
                parent.Add_navTab('dk_qtn_modify'+ruleFlag,'未出险问卷','/dk/dkquestnelog/examB.do?id='+id,callback);
            }else {
                parent.Add_navTab('dk_qtn_modify'+ruleFlag,'已出险问卷','/dk/dkquestnelog/examA.do?id='+id,callback);
            }
        }
    }
    function view(ruleFlag){
        parent.Add_navTab('dk_qtn_view'+ruleFlag,'查看问卷','/dk/dkquestnelog/view.do?ruleFlag='+ruleFlag,callback);
    }

    //===================下拉框查询控件结束===========================
</script>
</body>
</html>
